/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel;

import com.prefabware.commons.QualifiedName;
import com.prefabware.jmodel.code.JCodeOptions;

/**
 * a constructor is a special kind of method, used to create an instance of the type
 * @author sisele_job
 */
public class JConstructor extends JMethod {
	/**
	 * @param type
	 * @return the qualifiedName of a constructor of the given type
	 * e.g. type=java.lang.String
	 * returns java.lang.String.String
	 */
	public static QualifiedName getQualifiedName(JType type) {
		QualifiedName qualifiedName = type.getQualifiedName();
		return qualifiedName.append(qualifiedName.getSimpleName());
	};

	private JClass jClass;

	public JConstructor(JConstructorDeclaration declaration, JClass jClass) {
		// steckt die JClass nicht auch in der Declaration ?
		super(declaration);
		this.jClass = jClass;
	}

	@Override
	public JConstructorDeclaration getDeclaration() {
		return (JConstructorDeclaration) super.getDeclaration();
	}

	/**
	 * @return
	 * TODO use the returntype instead !
	 * in a way the returntype of a constructor is the declaring class
	 * in java the returntype of a class is omitted in the code
	 */
	public JClass getJClass() {
		return jClass;
	}

	@Override
	public String toString() {
		return "JConstructor [" + asCode(JCodeOptions.DEFAULT) + "]";
	}
}
